﻿using LBSoft.Common.DotNetConfig;
using LBSoft.Common.DotNetExt;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LBSoft.HplusAdmin.UserControl
{
    public partial class LoadSelfJS : System.Web.UI.UserControl
    {
        /// <summary>
        /// 当前时间格式-禁用浏览器css、js脚本缓存
        /// 开发：yyyyMMddHHmmss 正式：yyyyMMddHH
        /// </summary>
        public string vStr = DateTime.Now.ToString("yyyyMMddHH");

        private string scriptFormat = "<script src='{0}' type='text/javascript' language='javascript'></script>\r\n";

        protected void Page_Load(object sender, EventArgs e)
        {
            string SiteCssJsFormat = ConfigHelper.GetAppSettings("SiteCssJsFormat").ToString2();
            if (!string.IsNullOrEmpty(SiteCssJsFormat))
            {
                vStr = DateTime.Now.ToString(SiteCssJsFormat);
            }
            Literal lcInclude = new Literal();
            lcInclude.Text = this.GetIncludeCode();
            this.Controls.Add(lcInclude);
        }

        private string GetIncludeCode()
        {
            StringBuilder code = new StringBuilder();
            Page p = this.Parent.Page;
            string filePath = p.Request.FilePath;
            string fileName = filePath.Substring(0, filePath.LastIndexOf("/") + 1);
            fileName = filePath.Replace(fileName, "").Replace(".aspx", "");
            code.AppendFormat(scriptFormat, fileName + ".js?r=" + vStr);
            return code.ToString();
        }
    }
}